home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / P_ROBO31.ZIP / TAGTEAM1.PR < prev    next >
Text File  |  1989-10-23  |  5KB  |  143 lines

  1.   PROCEDURE TagTeam1;
  2.  
  3.   TeamAlly = "TagTeam2";
  4.  
  5.   {
  6.    Author: David Malmberg
  7.  
  8.    Strategy: Go to a random corner, raise shield, and blast away at any
  9.              robot in range.  Improve aim after every successful scan. If the
  10.              robot scans 20 times unsuccessfully, move to another random
  11.              corner.  Lower shields when moving; raise them when stopped.
  12.  
  13.              This robot can act individually or as part of a team with another
  14.              robot that follows an identical strategy, i.e., TagTeam2.  If
  15.              operating as a team, the two robots communicate their corners
  16.              to each other by setting COMM[10] to TagTeam1's corner and
  17.              COMM[11] to TagTeam2's corner.  They try to always pick different
  18.              random corners.
  19.  
  20.              WARNING: This Robot has not been designed to deal with
  21.              Obstructions effectively.
  22.   }
  23.  
  24.   CONST
  25.     NW_Corner = 1;
  26.     NE_Corner = 2;
  27.     SW_Corner = 3;
  28.     SE_Corner = 4;
  29.  
  30.   VAR { TagTeam1 "Global" variables }
  31.  
  32.     CornerX : ARRAY[1..4] OF Integer; {X coordinate of Corners}
  33.     CornerY : ARRAY[1..4] OF Integer; {Y coordinate of Corners}
  34.     StartAngle : ARRAY[1..4] OF Integer; {Starting scanning angles for Corners}
  35.  
  36.     Corner, { Current Corner }
  37.     Times,  { Number of times robot as scanned without success for enemy }
  38.     Angle,  { Scanning angle }
  39.     Delta,  { Scanning angle width }
  40.     Range   { Range/Distance to foe }  : Integer;
  41.  
  42.  
  43.     PROCEDURE Initialize;
  44.     BEGIN
  45.       CornerX[NW_Corner] := 10;
  46.       CornerY[NW_Corner] := 990;
  47.       StartAngle[NW_Corner] := 270;
  48.  
  49.       CornerX[NE_Corner] := 990;
  50.       CornerY[NE_Corner] := 990;
  51.       StartAngle[NE_Corner] := 180;
  52.  
  53.       CornerX[SW_Corner] := 10;
  54.       CornerY[SW_Corner] := 10;
  55.       StartAngle[SW_Corner] := 0;
  56.  
  57.       CornerX[SE_Corner] := 990;
  58.       CornerY[SE_Corner] := 10;
  59.       StartAngle[SE_Corner] := 90;
  60.     END; {Initialize}
  61.  
  62.  
  63.     PROCEDURE GOTO(x, y : Integer);
  64.       { Go to location X,Y on playing field. }
  65.     VAR Heading    : Integer;
  66.     BEGIN
  67.       LowerShield; {Moving target is hard to hit - so lower shield}
  68.  
  69.       { Find the heading we need to get to the desired spot. }
  70.       Heading := Angle_To(x, y);
  71.  
  72.       { Keep traveling at top speed until we are within 150 meters }
  73.       WHILE (distance(loc_x, loc_y, x, y) > 150) DO Drive(Heading, 100);
  74.  
  75.       { Cut speed, and creep the rest of the way. }
  76.       WHILE (distance(loc_x, loc_y, x, y) > 20) DO Drive(Heading, 20);
  77.  
  78.       { Stop driving, should coast to a stop. }
  79.       Drive(Heading, 0); {I.E., Stop}
  80.  
  81.       RaiseShield; {Still target is easy to hit - so raise shield}
  82.     END; {GoTo(X,Y)}
  83.  
  84.  
  85.     PROCEDURE Aim(VAR Ang : Integer; VAR Arc : Integer);
  86. {
  87.  Improve aim by doing a binary search of the target area.
  88.  I.E., divide the target area in two equal pieces and redefine
  89.  the target area to be the piece where the foe is found.
  90.  If the foe is not found, expand the search area to the
  91.  maximum arc of plus or minus 10 degrees.
  92. }
  93.     BEGIN
  94.       Times := 0; { Found enemy -- so set unsuccessful scan count to zero )
  95.       Arc := Arc DIV 2; { Divide search area in two. }
  96.       IF scan(Ang-Arc, Arc) <> 0 { Check piece "below" target angle. }
  97.       THEN Ang := Ang-Arc { If foe found, redefine target angle. }
  98.       ELSE IF scan(Ang+Arc, Arc) <> 0 { Check piece "above" target angle. }
  99.       THEN Ang := Ang+Arc { If foe found, redefine target angle. }
  100.       ELSE Arc := 10;
  101.       { Foe not found in either piece, expand search area to maximum arc. }
  102.     END; {Aim}
  103.  
  104.  
  105. PROCEDURE Do_Corner;
  106.   BEGIN {Do_Corner}
  107.     Times := 0; {Count of unsuccessful scans}
  108.     Angle := StartAngle[Corner] + 10; {Starting angle for scanning}
  109.     REPEAT
  110.       Delta := 10; { Start with widest scanning arc. }
  111.       Range := scan(Angle, Delta);
  112.       WHILE (Range > 40) AND (Range < 700) DO
  113.         { Must be far enough away to avoid self-damage. }
  114.         BEGIN
  115.           Aim(Angle, Delta); { Improve aim. }
  116.           IF ObjectScanned = Enemy THEN cannon(Angle, Range); { Fire!! }
  117.           Range := scan(Angle, Delta); { Is foe still in sights? }
  118.         END;
  119.       Angle := Angle + 20; { Look in adjacent target area. }
  120.       IF (Angle > (StartAngle[Corner] + 90))
  121.         THEN Angle := StartAngle[Corner] + 10;
  122.       Times := Times + 1;
  123.     UNTIL Times > 20; { Leave after 20 unsuccessful scans }
  124.   END; {Do_Corner}
  125.  
  126.  
  127.   BEGIN {TagTeam1 Main}
  128.     Initialize;
  129.     COMM[11] := 0; {Set Ally's corner (if any) to zero}
  130.     COMM[10] := 0; {Communicate My corner to Ally}
  131.     REPEAT
  132.       REPEAT
  133.         Corner := Random(3) + 1; {Pick a corner}
  134.       UNTIL Corner <> COMM[11]; {Need different corner than Ally}
  135.       COMM[10] := Corner; {Communicate My corner to Ally (if any)}
  136.       GoTo(CornerX[Corner], CornerY[Corner]);
  137.       { Move to selected corner. }
  138.       Do_Corner;
  139.     UNTIL Dead OR Winner;
  140.  
  141.   END; {TagTeam1 Main}
  142.  
  143.